package com.shizhanzhe.zxbapp.widget;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.Html;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import com.shizhanzhe.zxbapp.R;
import com.shizhanzhe.zxbapp.bean.UserBean;


/**
 * Created by YJ on 2018/10/15.
 */
public class ExitDialog extends Dialog {

    private ExitListener mExitListener;
    private ImageView iv_head;
    private TextView title;
    private TextView neirong;
    private TextView tv_false;
    private TextView tv_true;

    public void setExitListener(ExitListener exitListener) {
        mExitListener = exitListener;
    }

    public ExitDialog(@NonNull Context context) {
        super(context,R.style.my_dialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (null != getWindow()){
            WindowManager.LayoutParams lp = getWindow().getAttributes();
            lp.dimAmount = 0.5f;
            getWindow().setAttributes(lp);
        }
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        setContentView(R.layout.dialog_exit);
        title = findViewById(R.id.tv_title);
        neirong = findViewById(R.id.neirong);
        tv_false = findViewById(R.id.tv_false);
        tv_true = findViewById(R.id.tv_true);
        iv_head = findViewById(R.id.iv_head);
        tv_false.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mExitListener.chooseFalse();
            }
        });
        tv_true.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mExitListener.chooseTrue();
            }
        });
    }
    //退出账号设置
    public void setContent(String money){
        iv_head.setImageResource(R.mipmap.yhq);
        String textStr = "您已经赚了<font color=\"#FF4081\">"+money+"</font>元";
        title.setText(Html.fromHtml(textStr));
        neirong.setGravity(Gravity.CENTER);
        neirong.setText("加油赚更多吧");
        tv_false.setText("退出");
        textStr = "<font color=\"#FF4081\">继续赚</font>";
        tv_true.setText(Html.fromHtml(textStr));
    }
    //退出账号设置
    public void setContent2(String money){
        iv_head.setImageResource(R.mipmap.yhq);
        String textStr = "尚未绑定手机";
        title.setText(Html.fromHtml(textStr));
        neirong.setGravity(Gravity.CENTER);
        neirong.setText("退出后数据将不保留，个人信息将被清空，请绑定手机后退出，是否退出");
        tv_false.setText("是");
        textStr = "<font color=\"#FF4081\">否</font>";
        tv_true.setText(Html.fromHtml(textStr));
    }
    //替换任务
    public void setTask(String info){
        title.setText(info);
        neirong.setVisibility(View.GONE);
        tv_false.setText("取消");
        tv_true.setText("确定");
    }
    public void downQQ(){
        iv_head.setImageResource(R.mipmap.sign_true);
        tv_false.setText("暂不下载");
        tv_true.setText("立即下载");
        title.setText("提示");
        neirong.setText("请安装QQ浏览器后进行分享哦!");
    }
    @Override
    public void dismiss() {
        super.dismiss();
    }
    public interface ExitListener{
        void chooseTrue();
        void chooseFalse();
    }
}
